<template>
  <div class="ma-content-block  justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #status="{ record }">
            <a-tag v-if="record.status == 1" color="blue">正常</a-tag>
            <a-tag v-if="record.status == 2" color="blue">禁用</a-tag>
      </template>
      <template #type_id="{ record }">
            <a-tag color="blue">{{ record.type.name }}</a-tag>
      </template>
      <template #operationBeforeExtend="{ record }">
        <a-link @click="warehouseList(record)" v-auth="['warehouse:childs:index']">仓库配置</a-link>
      </template>
      
    </ma-crud>
    <a-drawer :footer="false" :width="1440" v-model:visible="visibleWarehouse">
        <template #title>
          仓库配置
        </template>
        <childs ref="warehousechildsRef" />
      </a-drawer>
      <div style="display:flex;justify-content: flex-end;width:100%;margin-bottom:24px">
        <div style='font-size:24px'>{{newDete}}</div>
      </div>
      <!-- <div class='flex'>
        <div style="margin-right:20px;overflow: scroll;" :style="{height:(ksHeght - 150) + 'px'}">
          <div :class='item.id == storeId?"act_box":"no_box"' @click='handleTab(item.id)' class="cursor" style='padding:12px;margin-bottom:12px' v-for='(item,index) in storeList.values' :key="index">
            <div class='flex align_center'>
              <div style="margin-right:8px">
                <img src="./img/tip.png" style="width:20px;height:20px;display:block"/>
              </div>
              <div style="font-size:16px;font-weight: 600;color:#415B73">{{item.name}}</div>
            </div>
            <img src="./img/line.png" style="width:100%;height:2px;display:block;margin:12px 0"/>
            <div class="flex">
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div>当前库存</div>
              </div>
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div style="font-size:18px;color:#00AB84;font-weight:600">5784</div>
                <div>件</div>
              </div>
              <div class="flex_1 flex align_center" style="font-size:14px;color:#7395B3">
                <div style="font-size:18px;color:#00AB84;font-weight:600">5784</div>
                <div>吨</div>
              </div>
            </div>
            <div class="flex">
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div>今日入库</div>
              </div>
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div style="font-size:18px;color:#00AB84;font-weight:600">5784</div>
                <div>件</div>
              </div>
              <div class="flex_1 flex align_center" style="font-size:14px;color:#7395B3">
                <div style="font-size:18px;color:#00AB84;font-weight:600">5784</div>
                <div>吨</div>
              </div>
            </div>
            <div class="flex">
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div>今日出库</div>
              </div>
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div style="font-size:18px;color:#00AB84;font-weight:600">5784</div>
                <div>件</div>
              </div>
              <div class="flex_1 flex align_center" style="font-size:14px;color:#7395B3">
                <div style="font-size:18px;color:#00AB84;font-weight:600">5784</div>
                <div>吨</div>
              </div>
            </div>
            <div class="flex">
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div>剩余库位</div>
              </div>
              <div class="flex_1 flex align_center" style="margin-right:10px;font-size:14px;color:#7395B3">
                <div style="font-size:18px;color:#00AB84;font-weight:600">5784</div>
                <div>个</div>
              </div>
              <div class="flex_1 flex align_center" style="font-size:14px;color:#7395B3"></div>
            </div>
          </div>
        </div>
        <div class="" :style="{width:(ksWight - 578) + 'px'}">
          <div class="flex align_center justify_between" style="padding:12px 20px;margin-bottom:16px">
            <div class="flex align_center">
              <div class="flex align_center" style="margin-right:16px">
                <div style="margin-right:6px">
                  <img src="./img/lu.png" style="width:20px;height:20px;display:block"/>
                </div>
                <div style="font-size:14px;color:#415B73">闲置仓位</div>
              </div>
              <div class="flex align_center" style="margin-right:16px">
                <div style="margin-right:6px">
                  <img src="./img/zi.png" style="width:20px;height:20px;display:block"/>
                </div>
                <div style="font-size:14px;color:#415B73">使用中仓位</div>
              </div>
              <div class="flex align_center" style="margin-right:16px">
                <div style="margin-right:6px">
                  <img src="./img/hui.png" style="width:20px;height:20px;display:block"/>
                </div>
                <div style="font-size:14px;color:#415B73">不可用仓位</div>
              </div>
              <div class="flex align_center" >
                <div style="margin-right:6px">
                  <img src="./img/hong.png" style="width:20px;height:20px;display:block"/>
                </div>
                <div style="font-size:14px;color:#415B73">搜索高亮显示放量</div>
              </div>
            </div>
            <div class="flex align_center relative">
              <input placeholder="输入订单号/品名/客户名称查询" class="input" />
              <div style="margin-left:10px" class="cursor">
                <img src="./img/search.png" style="width:36px;height:36px;display:block"/>
              </div>
              <div style="margin-left:10px;font-size:16px;line-height:16px;padding:10px 14px;border-radius: 18px;background:#00A0E9;color:#fff;">查看所在区域</div>
              <div class="act_box" style="padding: 12px;position: absolute;right:0;top:50px;z-index: 1;background:#fff;">
                <div class='flex align_center'>
                  <div style="margin-right:8px">
                    <img src="./img/tip.png" style="width:16px;height:16px;display:block"/>
                  </div>
                  <div style="font-size:16px;font-weight: 600;color:#415B73">区域视图</div>
                </div>
                <img src="./img/line.png" style="width:100%;height:2px;display:block;margin:12px 0"/>
                <div class=""  >
                  <div v-for='(item,index) in 5' :key="index">
                    <div class=" flex align_center justify_center" :class="index == tab?'act_title':'no_title'" style="margin-bottom:4px">
                      <div>棚盖区</div>
                    </div>
                    <div  style="margin-bottom:4px" v-if="index == 2">
                      <img src="./img/1haoxian.png" style="width:100%;height:22px;display:block"/>
                    </div>
                    <div style="margin-bottom:4px"  v-if="index == 2">
                      <img src="./img/2haoxian.png" style="width:100%;height:22px;display:block" />
                    </div> 
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="flex" style="overflow: scroll;" :style="{width:(ksWight - 578) + 'px',height:(ksHeght - 236) + 'px'}" v-dragscroll>
            <div class="" style="margin:0 4px" :class="storeArr.length > 10?'width50':'flex_1'" v-for="(item,index) in storeArr" :key="index" >
              <div class="flex align_center justify_center cursor lvbox" :class="storeArr.length > 10?'width50':'flex_1'" style="margin:4px 0;height:44px;" v-for="(items,indexs) in item.child" :key="indexs">
                <div>{{ index + 1 }}-{{ indexs + 1 }}</div>
              </div>
            </div>
          </div>
          
        </div>
      </div> -->
      
      
  </div>
</template>
<script setup>
import { ref, reactive,onMounted } from 'vue'
import warehouseMaster from '@/api/warehouse/warehouseMaster'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'
import childs from '@/views/warehouse/childs/index.vue'
import { request } from '@/utils/request.js'
import {dateFormat} from '@/utils/util.js'


const crudRef = ref()
const warehousechildsRef = ref()
const visibleWarehouse = ref(false)
const storeId = ref(0)
const storeList = reactive([])
const ksHeght = ref(0)
const ksWight = ref(0)
const newDete = ref(0)
const storeArr = reactive([
  
])
ksHeght.value = window.innerHeight
ksWight.value = window.innerWidth
newDete.value = dateFormat(new Date().getTime(),'Y年m月d日')
onMounted(()=>{
  getList()
})

const options = reactive({
  id: 'flyos_warehouse_master',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: warehouseMaster.getList,
  recycleApi: warehouseMaster.getRecycleList,
  add: {
    show: true,
    api: warehouseMaster.save,
    auth: ['warehouse:master:save']
  },
  edit: {
    show: true,
    api: warehouseMaster.update,
    auth: ['warehouse:master:update']
  },
  delete: {
    show: true,
    api: warehouseMaster.deletes,
    auth: ['warehouse:master:delete'],
    realApi: warehouseMaster.realDeletes,
    realAuth: ['warehouse:master:realDeletes']
  },
  recovery: {
    show: true,
    api: warehouseMaster.recoverys,
    auth: ['warehouse:master:recovery']
  },
  import: {
    show: true,
    url: 'warehouse/master/import',
    templateUrl: 'warehouse/master/downloadTemplate',
    auth: ['warehouse:master:import']
  },
  export: {
    show: true,
    url: 'warehouse/master/export',
    auth: ['warehouse:master:export']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: '仓库类型',
    dataIndex: 'type_id',
    align:'center',
    formType: 'select',
    hide:true,
    dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: 'warehouse/type/remote',
        // 指定组件接收的props
        props: { label: 'name', value: 'id' },
        // 开启分页
        openPage: true,
        // 远程请求配置项
        remoteOption: {
            // 按用户名排序
            sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
            // 设置查询的字段
            select: [ 'id', 'name' ],
            // 设置数据过滤
            filter: {
            },
            // 关联模型
            relations: [
            ]
        }
    }
  },
  {
    title: "仓库名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入仓库名称"
    }
  },
  {
    title: "横跨",
    dataIndex: "horizontal_span",
    formType: "input-number",
    search: true,
    commonRules: {
      required: true,
      message: "请输入横跨"
    }
  },
  {
    title: "纵跨",
    dataIndex: "release_span",
    formType: "input-number",
    search: true,
    commonRules: {
      required: true,
      message: "请输入纵跨"
    }
  },
  {
    title: "层级",
    dataIndex: "reaches",
    formType: "input-number",
    search: true,
    commonRules: {
      required: true,
      message: "请输入层级"
    }
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "switch",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    checkedValue: "1",
    uncheckedValue: "2"
  },
  // {
  //   title: "库存总量",
  //   dataIndex: "zong_num",
  //   formType: "input-number",
  //   search: true
  // },
  // {
  //   title: "库存余量",
  //   dataIndex: "yu_num",
  //   formType: "input-number",
  //   search: true
  // },
  // {
  //   title: "订单总量",
  //   dataIndex: "order_zong_num",
  //   formType: "input-number",
  //   search: true
  // },
  // {
  //   title: "订单余量",
  //   dataIndex: "order_yu_num",
  //   formType: "input-number",
  //   search: true
  // },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  // {
  //   title: "备注",
  //   dataIndex: "remark",
  //   formType: "input",
  //   hide: true
  // }
])

// 仓库列表
const getList = ()=>{
  request({
      url: 'warehouse/master/index',
      method: 'get',
      params:{}
    }).then(res=>{
      storeList.values = res.data.items
      storeId.value = res.data.items[0].id
      let heng = res.data.items[0].horizontal_span
      let zong = res.data.items[0].release_span
      for(let i = 1;i<=heng-0;i++){
        storeArr.push({heng:i})
      }
      storeArr.map((v,i)=>{
        let childArr = []
        for(let m = 1;m<=zong-0;m++){
          childArr.push({zong:m})
        }
        v.child = childArr
      })
    })
}
// 仓库数据
const getData = ()=>{
  request({
      url: 'warehouse/childs/remote',
      method: 'post',
      data:{
        openPage:false,
        remoteOption:{
          filter:{
            id:['>',storeId.value]
          }
        }
      }
    }).then(res=>{
    })
}


const warehouseList = (row) => {
  warehousechildsRef.value.open(row)
  visibleWarehouse.value = true
}

const numberOperation = (newValue, id, numberName) => {
  warehouseMaster.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  warehouseMaster.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const handleTab = (id)=>{
  storeId.value = id
}


</script>
<style scoped>
.flex{
  display: flex;
}
.flex_1{
  flex: 1;
}
.align_center{
  align-items: center;
}
.align_start{
  align-items: flex-start;
}
.align_end{
  align-items: flex-end;
}
.justify_center{
  justify-content: center;
}
.relative{
  position: relative;
}
.justify_between{
  justify-content: space-between;
}
.justify_around{
  justify-content: space-around;
}
.justify_end{
  justify-content: flex-end;
}
.flex_wrap{
  flex-wrap: wrap;
}
.flex_column{
  flex-direction: column;
}
.width0{
  width: 0upx;
}
.border_box{
  box-sizing: border-box;
}
.shodow{
  box-shadow: 0upx 3upx 6upx rgba(225, 226, 228, 0.86);
}
.text_center{
	text-align: center !important;
}
.act_box{
  border-radius: 9px;
  border: 2px solid #00A0E9;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.76) 0%, rgba(222, 239, 255, 0.76) 100%);
  width:260px;
  box-sizing: border-box;
}
.no_box{
  border-radius: 9px;
  border: 2px solid #fff;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.76) 0%, rgba(222, 239, 255, 0.76) 100%);
  width:260px;
  box-sizing: border-box;
  opacity:0.5;
}
.width50{
  width:120px;
}
.input{
    width:320px;
    padding:10px 20px;
    background: rgba(242,243,245);
    border:1px solid rgba(242,243,245);
    font-size:16px;
    line-height:16px;
    border-radius: 18px;
    outline: none;/*清除input点击之后的黑色边框*/
    box-sizing: border-box;
  }
  .input:focus{
    background: #fff;
    border:1px solid #1e80ff;
  }

/* 滚动条 */
body *::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
body *::-webkit-scrollbar-track {
  background: #fff;
  border-radius: 2px;
}
body *::-webkit-scrollbar-thumb {
  background: rgb(205, 206, 206);

  border-radius: 10px;
}
body *::-webkit-scrollbar-thumb:hover {
  background: #333;
}
body *::-webkit-scrollbar-corner {
  background: #fff;
}
.cursor{
  cursor: pointer
}

.lvbox{
  background:#74DB91;
  box-sizing: border-box;
  border-bottom:2px solid rgba(0, 0, 0, 0.15);
  color:#fff;
  border-radius:4px;
}
.huibox{
  background:#A8A8A8;
  box-sizing: border-box;
  border-bottom:2px solid rgba(0, 0, 0, 0.15);
  color:#fff;
  border-radius:4px;
}
.zibox{
  background:#C789ED;
  box-sizing: border-box;
  border-bottom:2px solid rgba(255, 255, 255, 0.40);
  color:#fff;
  border-radius:4px;
}
.hongbox{
  background:#E94829;
  box-sizing: border-box;
  border-bottom:2px solid rgba(255, 255, 255, 0.40);
  color:#fff;
  border-radius:4px;
}
.titleBox{
  margin-bottom:4px;
}
.act_title{
  font-size:14px;
  line-height:22px;
  font-weight: 600;
  color:#fff;
  background: #00A0E9;
}
.no_title{
  font-size:14px;
  line-height:22px;
  font-weight: 600;
  color:#00A0E9;
  background: rgba(0, 160, 233, 0.10);


}
.titleBox:last-child{
  margin-bottom:0px;
}




</style>
<script> export default { name: 'warehouse:master' } </script>